package com.pig.utils;

import java.util.concurrent.ThreadLocalRandom;

public class RedisConstants {
    public static final String LOGIN_CODE_KEY = "login:code:";
    public static final Long LOGIN_CODE_TTL = 2L;
    public static final String LOGIN_USER_KEY = "login:token:";
    public static final Long LOGIN_USER_TTL = 36000L;

    public static final Long CACHE_NULL_TTL = 2L;

    public static final Long CACHE_SHOP_TTL = 30L;
    public static final String CACHE_SHOP_KEY = "cache:shop:";

    public static final String LOCK_SHOP_KEY = "lock:shop:";
    public static final Long LOCK_SHOP_TTL = 10L;

    public static final Long CACHE_PRODUCT_TTL = 30L;
    public static final String CACHE_PRODUCT_KEY = "cache:product:";

    public static final String LOCK_PRODUCT_KEY = "lock:product:";
    public static final Long LOCK_PRODUCT_TTL = 10L;

    public static final String SECKILL_STOCK_KEY = "seckill:stock:";
    public static final String BLOG_LIKED_KEY = "blog:liked:";
    public static final String FEED_KEY = "feed:";
    //public static final String SHOP_GEO_KEY = "shop:geo:";
    public static final String PRODUCT_GEO_KEY = "product:geo:";
    public static final String USER_SIGN_KEY = "sign:";

    // 定义一个随机时间范围，用于解决缓存雪崩问题
    private static final int RANDOM_TTL_RANGE = 30;
    // 获取随机过期时间
    public static Long getRandomTTL(long ttl) {
        return ttl + ThreadLocalRandom.current().nextLong(RANDOM_TTL_RANGE);
    }
}
